/**查询全部用户**/
function queryCourse() {
    $.ajax({
        type: "GET",
        url: "rest/course/list",
        dataType: "json",
        success: function (data) {
            var courseList = data.data;
            if (courseList.lenght == 0) {
                $("#show_list").html("暂时查不到您要的数据！");
            } else {
                var courseListHtml = "<tr><th><input id='checked-all' type='checkbox'><label>全选</label></th><th>课程名称</th><th>课程教师</th><th>课程时长</th><th>课程类型</th><th>操作</th></tr>";
                $.each(courseList, function (i, n) {
                    i += 1;
                    courseListHtml = courseListHtml + "<tr><td class='list-id'><input type='checkbox'><label>"
                        + i + "</label></td><td>"
                        + n.name + "</td><td>"
                        + n.teacher + "</td><td>"
                        + n.coursenumber + "</td><td>"
                        + n.type + "</td><td class='user-edit'><a  class='editBtn' data-id='"
                        + n.id + "'>编辑</a><a class='deleteBtn'  data-id='"
                        + n.id + "'>删除</a></td></tr>";
                });
                $("#show_list").html(courseListHtml);
                $(".deleteBtn").click(function () {
                    delCourse($(this).attr("data-id"));
                });
                $(".editBtn").click(function () {
                    updateCourse($(this).attr("data-id"));
                })

            }
        }
    });
}

/**
 * @decription:添加案例
 *  @param：#submit 提交
 */

function addCourse() {
    window.location.href = "rest/course/addCourse";//跳转到添加页面

}

/**
 * @decription:删除案例
 */
function delCourse(courseId) {
    var param = "courseId=" + courseId;
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "rest/course/del",
        data: param,
        success: function () {
            queryCourse();
        }
    });
}

/**
 * @decription:更新案例
 */
function updateCourse(courseId) {
    window.location.href = "rest/course/editorCourse" + "?id=" + courseId;

}
queryCourse();